package com.cinema.service.impl;

import com.cinema.dao.OrderDao;
import com.cinema.entity.Ordering;
import com.cinema.entity.User;
import com.cinema.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderDao orderDao;
    @Override
    //插入订单信息
    public int insertOrder(Ordering order) {
        //判断传入的订单是否为空
        if (order != null){
            //不为空则插入
            int effectedNum = orderDao.insertOrder(order);
            if (effectedNum > 0 ){
                return 1;
            }
        }
        return -1;
    }

    @Override
    public List<Ordering> selectOrder(int userId) {
        List<Ordering> orderinglist = new ArrayList<>();
        //判断传入的用户id是否为空,不为空则插入
        if (userId > 0){
            orderinglist = orderDao.selectOrder(userId);
        }else {
            return null;
        }
        //判断列表是否为空
        if (orderinglist.size() > 0){
            return orderinglist;
        }
        return null;
    }

    @Override
    public int deleteOrder(int userId) {
        if (userId > 0 ){
            return orderDao.deleteOrder(userId);
        }
        return 0;
    }
}
